from django.db import models

from apps.users.models import UserProfile
from apps.project.models import Project

# Create your models here.


class Case(models.Model):
    """
        测试用例模型
        """
    case_type = (
        ('web', 'Web自动化'),
        ('app', 'App自动化'),
        ('interface', '接口自动化'),)
    case_status = (
        (0, 'SUCCESS'),
        (1, 'FAILURE'),
        (2, 'ERROR'),
        (3, 'SKIP'),
        (4, 'idle')
    )
    case_level = (
        ('low', '低'),
        ('medium', '中'),
        ('high', '高'),)

    case_num = models.CharField(max_length=20, verbose_name=u'用例编号')
    name = models.CharField(max_length=18, verbose_name=u'用例标题')
    project = models.ForeignKey(Project, default=1, on_delete=models.CASCADE, verbose_name='测试项目id')
    type = models.CharField(max_length=20, choices=case_type, default='web', verbose_name=u'用例类型')
    status = models.CharField(max_length=20, choices=case_status, default=4, verbose_name=u'结果')
    level = models.CharField(max_length=20, choices=case_level, default='low', verbose_name=u'用例级别')
    creator = models.ForeignKey(UserProfile, verbose_name=u'创建人', on_delete=models.SET_NULL, null=True, blank=True)
    detail = models.CharField(max_length=50, null=True, blank=True, verbose_name=u'用例描述')
    add_time = models.DateTimeField(auto_now_add=True, verbose_name=u'创建时间')
    edit_time = models.DateTimeField(auto_now=True, verbose_name=u'修改时间')

    class Meta:
        db_table = 't_case'
        verbose_name = u'用例库'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
